package com.billdowney.controller.manage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.billdowney.annotation.AuthRoleAllowed;
import com.billdowney.annotation.SystemLogInfo;
import com.billdowney.controller.BaseController;
import com.billdowney.entity.base.EntityStatus;
import com.billdowney.entity.user.UserInfo;
import com.billdowney.entity.user.UserLoginInfo;
import com.billdowney.service.interfaces.user.UserInfoService;
import com.billdowney.util.auth.AuthRoleConst;
import com.billdowney.util.log.SystemLogHandleType;
import com.billdowney.util.return_type.ReturnData;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @ClassName: UserManageController
 * @Description: 用户管理控制器
 * @author 超级小富翁 - BillDowney
 * @date 2018年2月1日 下午6:29:07
 */
@RestController
@RequestMapping(value = "/userManage", method = { RequestMethod.POST })
@Api(tags = "用户管理控制器")
public class UserManageController extends BaseController {

	@Autowired
	private UserInfoService userInfoService;

	@AuthRoleAllowed(AuthRoleConst.ROLE_ADMIN)
	@RequestMapping(value = "/addLoginUserInfo")
	@SystemLogInfo(value = "管理员添加用户信息：{username}", handleType = SystemLogHandleType.save)
	@ApiOperation(value = "管理员添加用户信息", response = UserInfo.class)
	@ApiImplicitParams({ @ApiImplicitParam(name = "username", value = "用户名"),
			@ApiImplicitParam(name = "password", value = "未加密密码") })
	public ReturnData addLoginUserInfo(String username, String password) throws Exception {
		UserLoginInfo userLoginInfo = new UserLoginInfo();
		userLoginInfo.setUsername(username);
		userLoginInfo.setPassword(password);
		return new ReturnData(userInfoService.addUserLoginInfo(userLoginInfo));
	}

	@AuthRoleAllowed(AuthRoleConst.ROLE_ADMIN)
	@RequestMapping(value = "/queryUser")
	@ApiOperation(value = "分页查询用户信息", response = UserInfo.class)
	@ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "查询页码", defaultValue = "1"),
			@ApiImplicitParam(name = "pageSize", value = "查询数量", defaultValue = "10"),
			@ApiImplicitParam(name = "keyword", value = "查询关键字"), @ApiImplicitParam(name = "status", value = "数据状态") })
	public ReturnData queryUser(@RequestParam(defaultValue = "1") int pageNum,
			@RequestParam(defaultValue = "10") int pageSize, String keyword, EntityStatus status) throws Exception {
		return new ReturnData(userInfoService.queryUserByPaging(pageNum, pageSize, keyword, status));
	}

	@AuthRoleAllowed(AuthRoleConst.ROLE_ADMIN)
	@RequestMapping(value = "/delUser")
	@SystemLogInfo(value = "逻辑删除用户信息：{ids}", handleType = SystemLogHandleType.logicDelete)
	@ApiOperation(value = "删除用户信息", notes = "根据用户id来逻辑删除用户数据", response = String.class)
	@ApiImplicitParam(name = "ids", value = "逗号隔开的id串")
	public ReturnData delUser(@RequestParam String[] ids) throws Exception {
		return new ReturnData("总共" + ids.length + "条数据，成功删除" + userInfoService.delUser(ids) + "条数据");
	}

}
